WHEN condition

Syntax: WHEN condition
Location: QL ROM (post JM), THOR XVI, Not SMSQ/E

WHEN is used to identify the start of a SuperBASIC structure which is used to surround lines of SuperBASIC code which should be executed whenever the given condition is met. The condition is not checked when a variable is READ, or INPUT.

The syntax of the SuperBASIC structure can take two forms:

WHEN condition:statement {:statement}
or   
WHEN condition
{statement}
.. 
END WHEN

The condition can be anything which is accepted by the IF command, provided that it begins with the name of a variable. The variable cannot be an array.

When a program is run, the interpreter will make a note of the variable being tested and then jump to the statement following the END WHEN statement (unless the in-line format is used when control jumps to the next line if END WHEN does not appear on that line).  

Great care must however, be taken where the condition refers to more than one variable, as an 'error in expression' will be reported if a variable is not defined when the condition is tested.

Blocks cannot be mixed together.

WHEN processing is turned off by the command:

WHEN anything

and also when the NEW, CLEAR, LOAD, LRUN, MERGE, and MRUN commands are issued. You can also switch off WHEN processing on a given variable (eg. b) by entering:
WHEN b

Example:   
WHEN a>100 AND a<1000: PRINT 'A is now in the range 100-1000': a=a+100

CROSS-REFERENCE:
Other SuperBASIC structures are WHEN ERRor, SELect ON and IF..END IF.
END WHEN defines the end of a WHEN structure.
